{% extends 'base.html' %}
{% block content %}

<script type="text/javascript">
	app.controller('content',function ($scope,$http) {
		$scope.name='app'
		$scope.show_creat_app=function () {
			$scope.createing_app=true
		}
		$scope.apps=[]
		$scope.create_app=function (flow,appcode) {
			var postData = {
				order:['create_app','get_flows'],
				create_app:{flow:flow,appcode:appcode},
				get_flows:{}
			}
			$http.post('',postData)
				.success(function(data, status, headers, config) {  
					$scope.apps=data.get_flows.flows
					if(data.msg){
						alert(data.msg)
					}
				}).error(function(data, status, headers, config) {  
				    alert('有错误,返回码为:'+status)
				});
		}
		function init() {
			var postData = {
				get_flows:{}
			}
			$http.post('',postData)
				.success(function(data, status, headers, config) {  
					$scope.apps=data.get_flows.flows
					if(data.msg){
						alert(data.msg)
					}
				}).error(function(data, status, headers, config) {  
				    alert('有错误,返回码为:'+status)
				});
		}
		init()
		$scope.add_version=function (appcode) {
			var postData = {
				order:['add_version','get_flows'],
				add_version:{appcode:appcode,vercode:$scope.vercode},
				get_flows:{}
			}
			$http.post('',postData)
				.success(function(data, status, headers, config) {  
					$scope.apps=data.get_flows.flows
					$scope.vercode=''
					if(data.msg){
						alert(data.msg)
					}
				}).error(function(data, status, headers, config) {  
				    alert('有错误,返回码为:'+status)
				});
		}
		$scope.add_qa=function (appcode,vercode) {
			var postData = {
				order:['add_qa','get_flows'],
				add_qa:{appcode:appcode,vercode:vercode},
				get_flows:{}
			}
			$http.post('',postData)
				.success(function(data, status, headers, config) {  
					$scope.apps=data.get_flows.flows
					$scope.vercode=''
					if(data.msg){
						alert(data.msg)
					}
				}).error(function(data, status, headers, config) {  
				    alert('有错误,返回码为:'+status)
				});
		}
		$scope.add_rel_qa=function (appcode,vercode) {
			var postData = {
				order:['add_rel_qa','get_flows'],
				add_rel_qa:{appcode:appcode,vercode:vercode},
				get_flows:{}
			}
			$http.post('',postData)
				.success(function(data, status, headers, config) {  
					$scope.apps=data.get_flows.flows
					$scope.vercode=''
					if(data.msg){
						alert(data.msg)
					}
				}).error(function(data, status, headers, config) {  
				    alert('有错误,返回码为:'+status)
				});
		}
		$scope.add_sub=function (appcode,vercode) {
			var postData = {
				order:['add_sub','get_flows'],
				add_sub:{appcode:appcode,vercode:vercode},
				get_flows:{}
			}
			$http.post('',postData)
				.success(function(data, status, headers, config) {  
					$scope.apps=data.get_flows.flows
					$scope.vercode=''
					if(data.msg){
						alert(data.msg)
					}
				}).error(function(data, status, headers, config) {  
				    alert('有错误,返回码为:'+status)
				});
		}
	})
</script>
<div ng-controller='content'>
	<button type="button" class="btn btn-success" ng-click='show_creat_app()'>添加App</button>
	<div ng-show='createing_app'>
		<select name="" id="" ng-model='flow'>
			<option value="">---</option>
			<option value='FlowCD'>FlowCD</option>
			<option value='FlowNJ'>FlowNJ</option>
		</select>
		<input type="text" name="test" value="" ng-model='appcode'/>
		<button type="button" class="btn btn-info" ng-click='create_app(flow,appcode)'>确定</button>
	</div>
	<div>
		<table class='table'>
			<tr ng-repeat='flow in apps'>
				<span>
					<td >
					<span ng-bind='flow.app'></span>
					<td>
					<td ng-if='flow.flow_type=="FlowCD"'> 
						<table class='table'>
							<tr ng-repeat='ver in flow.version'>
								<td><span ng-bind='ver.vercode'></span></td>
								<td>
									<span ng-if='ver.dev_qa' ng-bind='ver.dev_qa'></span>
									<span ng-if='!ver.dev_qa'><a href="#" ng-click='add_qa(flow.app,ver.vercode)'>+</a></span>
								</td>
								<td>
									<span ng-if='!ver.dev_qa'>waiting DEV QA</span>
									<span ng-if='ver.rel_qa' ng-bind='ver.rel_qa'></span>
									<span ng-if='ver.dev_qa && !ver.rel_qa'> <a href="#" ng-click='add_rel_qa(flow.app,ver.vercode)'>+</a></span>
								</td>
								<td ng-if='ver.rel_qa'>
									<table>
										<tr ng-repeat='sub in ver.subs track by $index'>
											<td>
												<span ng-bind='sub'></span>
												<a href="">yes</a>
											</td>
										</tr>
										<tr>
											<a href="" ng-click='add_sub(flow.app,ver.vercode)'>+</a>
										</tr>
									</table>
								</td>
							</tr>
							
						</table>

						<a ng-click='add_version(flow.app)' href='#'>+</a>
					</td>

					<td ng-if='flow.flow_type=="FlowNJ"'>
						NJJJ
					</td>
				</span>
			
			</tr>
			
		</table>
	</div>

	<div>
		<input type="" ng-model='vercode'>
	</div>
</div>
{% endblock %}